SpreadJS Documentation
Handle Callback action on a Hyperlink Cell
SpreadJS Documentation > Developer's Guide > Managing the User Interface > Working with Cell Types > Setting a Hyperlink Cell > Handle Callback action on a Hyperlink Cell

You can execute callback actions on a hyperlink cell using the onClickAction method in the HyperLink class.

Using Code

The following code sets a callback action to the hyperlink.

When the hyperlink is clicked by a user, the callback action will be executed. As a result, the sheet name will be changed to the name "Hyperlink" and the sheet tab color will be changed to red.

JavaScript
Copy Code

var h = new GC.Spread.Sheets.CellTypes.HyperLink();
sheet.setCellType(3, 2, h, GC.Spread.Sheets.SheetArea.viewport);

h.text('Spread.Sheets Site');

h.linkColor('blue');

// Set a callback action to the hyperlink

h.onClickAction(function () {
   var setSheetTabColor = {
      canUndo: true,
      execute: function (context, options, isUndo) {
      sheet.name('Hyperlink');
      sheet.options.sheetTabColor = 'red';
      }
   };
   var commandManager = spread.commandManager();
   var commandName = 'setSheetTabStyle';
   

// code to register this callback to the commandManager
   commandManager.register(commandName, setSheetTabColor, null, false, false, false, false);
   commandManager.execute({cmd: commandName});
});

You can also control whether the active cell should be moved to the hyperlink cell when the hyperlink is clicked by a user using the activeOnClick method in the HyperLink class.

Using Code

The following code can be used to get and set whether to move to the active cell when the hyperlink is clicked.

JavaScript
Copy Code

h.activeOnClick(true);